
def all_perms(str):
	if len(str) <= 1:
		yield str
	else:
		for perm in all_perms(str[1:]):
			for i in range(len(perm)+1):
				yield perm[:i] + str[0:1] + perm[i:]

list = []

prange = []
for i in range(1, 10):
	prange.append(str(i))

for perm in all_perms(prange):
	for i in range(1, 6):
		for j in range(i+1, 6):
			x = int("".join(perm[:i]))
			y = int("".join(perm[i:j]))
			z = int("".join(perm[j:]))
			if x * y == z and list.count(z) == 0:
				print "%d * %d = %d" % (x, y, z)
				list.append(z)

print sum(list)
